package com.cawis.util;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

@Slf4j
public class Utils {

    /**
     * 根据数字长度补零
     *
     * @param length
     * @param num
     * @return
     */
    public static String pad(int length, long num) {
        return String.format("%0".concat(String.valueOf(length)).concat("d"), num);
    }

    /**
     * 冒泡排序
     *
     * @param arr
     * @return
     */
    public static Integer[] bubbleSort(Integer[] arr) {
        Integer num;
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    num = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = num;
                }
            }
        }
        return arr;
    }

    public static void main(String[] args) {
        Integer[] arr = {100, 324, 24, 12, 44, 1};
        System.out.println(Arrays.asList(arr));
        System.out.println(Arrays.asList(bubbleSort(arr)));
    }

}
